home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1US2LNP (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  8.2 KB  |  321 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import com.sun.java.swing.plaf.SplitPaneUI;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Graphics;
  9. import java.awt.LayoutManager;
  10.  
  11. public class JSplitPane extends JComponent implements Accessible {
  12.    public static final int VERTICAL_SPLIT = 0;
  13.    public static final int HORIZONTAL_SPLIT = 1;
  14.    public static final String LEFT = "left";
  15.    public static final String RIGHT = "right";
  16.    public static final String TOP = "top";
  17.    public static final String BOTTOM = "bottom";
  18.    public static final String DIVIDER = "divider";
  19.    public static final String ORIENTATION_PROPERTY = "orientation";
  20.    public static final String CONTINUOUS_LAYOUT_PROPERTY = "continuousLayout";
  21.    public static final String DIVIDER_SIZE_PROPERTY = "dividerSize";
  22.    public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = "oneTouchExpandable";
  23.    public static final String LAST_DIVIDER_LOCATION_PROPERTY = "lastDividerLocation";
  24.    protected int orientation;
  25.    protected boolean continuousLayout;
  26.    protected Component leftComponent;
  27.    protected Component rightComponent;
  28.    protected int dividerSize;
  29.    protected boolean oneTouchExpandable;
  30.    protected int lastDividerLocation;
  31.  
  32.    public JSplitPane() {
  33.       this(1, false, new JButton("left button"), new JButton("right button"));
  34.    }
  35.  
  36.    public JSplitPane(int newOrientation) {
  37.       this(newOrientation, false);
  38.    }
  39.  
  40.    public JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent) {
  41.       this(newOrientation, false, newLeftComponent, newRightComponent);
  42.    }
  43.  
  44.    public JSplitPane(int newOrientation, boolean newContinuousLayout) {
  45.       this(newOrientation, newContinuousLayout, (Component)null, (Component)null);
  46.    }
  47.  
  48.    public JSplitPane(int newOrientation, boolean newContinuousLayout, Component newLeftComponent, Component newRightComponent) {
  49.       ((Container)this).setLayout((LayoutManager)null);
  50.       this.orientation = newOrientation;
  51.       if (this.orientation != 1 && this.orientation != 0) {
  52.          throw new IllegalArgumentException("cannot create JSplitPane, orientation must be one of JSplitPane.HORIZONTAL_SPLIT or JSplitPane.VERTICAL_SPLIT");
  53.       } else {
  54.          this.continuousLayout = newContinuousLayout;
  55.          if (newLeftComponent != null) {
  56.             this.setLeftComponent(newLeftComponent);
  57.          }
  58.  
  59.          if (newRightComponent != null) {
  60.             this.setRightComponent(newRightComponent);
  61.          }
  62.  
  63.          this.updateUI();
  64.       }
  65.    }
  66.  
  67.    protected void addImpl(Component comp, Object constraints, int index) {
  68.       if (constraints != null && !(constraints instanceof String)) {
  69.          throw new IllegalArgumentException("cannot add to layout: constraint must be a string (or null)");
  70.       } else {
  71.          if (constraints == null) {
  72.             if (this.getLeftComponent() == null) {
  73.                constraints = "left";
  74.             } else if (this.getRightComponent() == null) {
  75.                constraints = "right";
  76.             }
  77.          }
  78.  
  79.          if (constraints == null || !constraints.equals("left") && !constraints.equals("top")) {
  80.             if (constraints != null && (constraints.equals("right") || constraints.equals("bottom"))) {
  81.                Component var5 = this.getRightComponent();
  82.                if (var5 != null) {
  83.                   this.remove(var5);
  84.                }
  85.  
  86.                this.rightComponent = comp;
  87.                index = -1;
  88.             } else if (constraints != null && constraints.equals("divider")) {
  89.                index = -1;
  90.             }
  91.          } else {
  92.             Component toRemove = this.getLeftComponent();
  93.             if (toRemove != null) {
  94.                this.remove(toRemove);
  95.             }
  96.  
  97.             this.leftComponent = comp;
  98.             index = -1;
  99.          }
  100.  
  101.          super.addImpl(comp, constraints, index);
  102.       }
  103.    }
  104.  
  105.    public AccessibleContext getAccessibleContext() {
  106.       if (super.accessibleContext == null) {
  107.          super.accessibleContext = new AccessibleJSplitPane(this);
  108.       }
  109.  
  110.       return super.accessibleContext;
  111.    }
  112.  
  113.    public Component getBottomComponent() {
  114.       return this.rightComponent;
  115.    }
  116.  
  117.    public int getDividerLocation() {
  118.       SplitPaneUI ui = this.getUI();
  119.       return ui != null ? ui.getDividerLocation() : -1;
  120.    }
  121.  
  122.    public int getDividerSize() {
  123.       return this.dividerSize;
  124.    }
  125.  
  126.    public int getLastDividerLocation() {
  127.       return this.lastDividerLocation;
  128.    }
  129.  
  130.    public Component getLeftComponent() {
  131.       return this.leftComponent;
  132.    }
  133.  
  134.    public int getMaximumDividerLocation() {
  135.       SplitPaneUI ui = this.getUI();
  136.       return ui != null ? ui.getMaximumDividerLocation() : -1;
  137.    }
  138.  
  139.    public int getMinimumDividerLocation() {
  140.       SplitPaneUI ui = this.getUI();
  141.       return ui != null ? ui.getMinimumDividerLocation() : -1;
  142.    }
  143.  
  144.    public int getOrientation() {
  145.       return this.orientation;
  146.    }
  147.  
  148.    public Component getRightComponent() {
  149.       return this.rightComponent;
  150.    }
  151.  
  152.    public Component getTopComponent() {
  153.       return this.leftComponent;
  154.    }
  155.  
  156.    public SplitPaneUI getUI() {
  157.       return (SplitPaneUI)super.ui;
  158.    }
  159.  
  160.    public String getUIClassID() {
  161.       return "SplitPaneUI";
  162.    }
  163.  
  164.    public boolean isContinuousLayout() {
  165.       return this.continuousLayout;
  166.    }
  167.  
  168.    public boolean isOneTouchExpandable() {
  169.       return this.oneTouchExpandable;
  170.    }
  171.  
  172.    protected void paintChildren(Graphics g) {
  173.       super.paintChildren(g);
  174.       SplitPaneUI ui = this.getUI();
  175.       if (ui != null) {
  176.          Graphics tempG = g.create();
  177.          ui.finishedPaintingChildren(this, tempG);
  178.          tempG.dispose();
  179.       }
  180.  
  181.    }
  182.  
  183.    public void remove(int index) {
  184.       Component comp = ((Container)this).getComponent(index);
  185.       if (comp == this.leftComponent) {
  186.          this.leftComponent = null;
  187.       } else if (comp == this.rightComponent) {
  188.          this.rightComponent = null;
  189.       }
  190.  
  191.       super.remove(index);
  192.    }
  193.  
  194.    public void remove(Component component) {
  195.       if (component == this.leftComponent) {
  196.          this.leftComponent = null;
  197.       } else if (component == this.rightComponent) {
  198.          this.rightComponent = null;
  199.       }
  200.  
  201.       super.remove(component);
  202.    }
  203.  
  204.    public void removeAll() {
  205.       this.leftComponent = this.rightComponent = null;
  206.       super.removeAll();
  207.    }
  208.  
  209.    public void resetToPreferredSizes() {
  210.       SplitPaneUI ui = this.getUI();
  211.       if (ui != null) {
  212.          ui.resetToPreferredSizes();
  213.       }
  214.  
  215.    }
  216.  
  217.    public void setBottomComponent(Component comp) {
  218.       this.setRightComponent(comp);
  219.    }
  220.  
  221.    public void setContinuousLayout(boolean newContinuousLayout) {
  222.       boolean oldCD = this.continuousLayout;
  223.       this.continuousLayout = newContinuousLayout;
  224.       ((JComponent)this).firePropertyChange("continuousLayout", oldCD, newContinuousLayout);
  225.    }
  226.  
  227.    public void setDividerLocation(double proportionalLocation) {
  228.       if (!(proportionalLocation < (double)0.0F) && !(proportionalLocation > (double)1.0F)) {
  229.          if (this.getOrientation() == 0) {
  230.             this.setDividerLocation((int)((double)(((JComponent)this).getHeight() - this.getDividerSize()) * proportionalLocation));
  231.          } else {
  232.             this.setDividerLocation((int)((double)(((JComponent)this).getWidth() - this.getDividerSize()) * proportionalLocation));
  233.          }
  234.  
  235.       } else {
  236.          throw new IllegalArgumentException("proportional location must be between 0.0 and 1.0.");
  237.       }
  238.    }
  239.  
  240.    public void setDividerLocation(int location) {
  241.       SplitPaneUI ui = this.getUI();
  242.       if (ui != null) {
  243.          ui.setDividerLocation(location);
  244.       }
  245.  
  246.    }
  247.  
  248.    public void setDividerSize(int newSize) {
  249.       int oldSize = this.dividerSize;
  250.       if (oldSize != newSize) {
  251.          this.dividerSize = newSize;
  252.          ((JComponent)this).firePropertyChange("dividerSize", oldSize, newSize);
  253.       }
  254.  
  255.    }
  256.  
  257.    public void setLastDividerLocation(int newLastLocation) {
  258.       int oldLocation = this.lastDividerLocation;
  259.       this.lastDividerLocation = newLastLocation;
  260.       ((JComponent)this).firePropertyChange("lastDividerLocation", oldLocation, newLastLocation);
  261.    }
  262.  
  263.    public void setLeftComponent(Component comp) {
  264.       if (comp == null) {
  265.          if (this.leftComponent != null) {
  266.             this.remove(this.leftComponent);
  267.             this.leftComponent = null;
  268.          }
  269.       } else {
  270.          ((Container)this).add(comp, "left");
  271.       }
  272.  
  273.    }
  274.  
  275.    public void setOneTouchExpandable(boolean newValue) {
  276.       boolean oldValue = this.oneTouchExpandable;
  277.       this.oneTouchExpandable = newValue;
  278.       ((JComponent)this).firePropertyChange("oneTouchExpandable", oldValue, newValue);
  279.       ((Component)this).repaint();
  280.    }
  281.  
  282.    public void setOrientation(int orientation) {
  283.       if (orientation != 0 && orientation != 1) {
  284.          throw new IllegalArgumentException("JSplitPane: orientation must be one of JSplitPane.VERTICAL_SPLIT or JSplitPane.HORIZONTAL_SPLIT");
  285.       } else {
  286.          int oldOrientation = this.orientation;
  287.          this.orientation = orientation;
  288.          ((JComponent)this).firePropertyChange("orientation", oldOrientation, orientation);
  289.       }
  290.    }
  291.  
  292.    public void setRightComponent(Component comp) {
  293.       if (comp == null) {
  294.          if (this.rightComponent != null) {
  295.             this.remove(this.rightComponent);
  296.             this.rightComponent = null;
  297.          }
  298.       } else {
  299.          ((Container)this).add(comp, "right");
  300.       }
  301.  
  302.    }
  303.  
  304.    public void setTopComponent(Component comp) {
  305.       this.setLeftComponent(comp);
  306.    }
  307.  
  308.    public void setUI(SplitPaneUI ui) {
  309.       if ((SplitPaneUI)super.ui != ui) {
  310.          super.setUI(ui);
  311.          ((Container)this).invalidate();
  312.       }
  313.  
  314.    }
  315.  
  316.    public void updateUI() {
  317.       this.setUI((SplitPaneUI)UIManager.getUI(this));
  318.       ((Container)this).invalidate();
  319.    }
  320. }
  321.